<template>
	<view class='content'>
		<view class="btns">
			<u-button class="btn" type="primary" @click="gotoupload" text="上传维修记录"></u-button>
		</view>
		<view class="message-box">
			<view class="message-item" v-for="(item,index) in list" :key='index' @click="gotoDetail(item)">
				<view class="flex">
					<view class='msgtitle'>维修时间：{{ item.ctime}}</view>
					
				</view>
				<view class="flex">
					<view class="money">
						<view class="">
							设备编号：{{ item.macno}}
						</view>
						<view class="">
							维修记录：{{ item.content}}
						</view>
						
					</view>
					<view class="">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loading',
				page: 1,
				pagesize: 10,
				list: [],
				ReachBottom: false
			}
		},
		onLoad() {
			this.gethomeData()
		},
		// 上拉加载
		onReachBottom() {
		
			let _self = this
			console.log('reach')
		
			uni.showNavigationBarLoading()
			// console.log('reach');
			if(_self.ReachBottom){
				_self.status = 'loading'
				setTimeout(function() {
					_self.page++;
					_self.gethomeData();
					uni.hideNavigationBarLoading()
				}, 2000);
			}
			
		
		},
		onPullDownRefresh() {
			//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
			console.log('refresh');
			setTimeout(function() {
				this.page = 1
				uni.stopPullDownRefresh(); //停止下拉刷新动画
				this.gethomeData()
			}, 1000);
		},
		methods: {
			gotoupload(){
				uni.navigateTo({
					url: '/pages/admin/errorService'
				})
			},
			gotoDetail(item){
				uni.navigateTo({
					url: '/pages/admin/serviceDetail?id='+item.id
				})
			},
			changeTime(time){
				const dateObj = new Date(time * 1000);
				 
				// 获取年月日时分秒
				let year = dateObj.getFullYear();
				let month = (dateObj.getMonth() + 1).toString().padStart(2, '0');
				let day = dateObj.getDate().toString().padStart(2, '0');
				let hours = dateObj.getHours().toString().padStart(2, '0');
				let minutes = dateObj.getMinutes().toString().padStart(2, '0');
				let seconds = dateObj.getSeconds().toString().padStart(2, '0');
				
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
			},	
			gethomeData(){
				var _this = this
				uni.request({
					url: 'http://www.yndzfl.cn/wxsite/Staff/repairList',
					method: 'POST',
					header:{
						"Content-Type" : "application/x-www-form-urlencoded"
					},
					data: {
						token: uni.getStorageSync('token'),
						page: _this.page,
						pagesize: _this.pagesize
					},
					success(res) {
						console.log(res)
						if(res.data.code == 1){
							if (res.data.data.length < 10) {
								_this.ReachBottom = false
								// uni.showToast({
								// 	title: '没有更多数据了',
								// 	icon: "none"
								// });
								_this.status = 'nomore'
							}else{
								_this.ReachBottom = true
								_this.status = 'loadmore'
							}
							if (_this.page != 1) {
								_this.list = _this.list.concat(res.data.data)
							} else {
								_this.list = res.data.data
							}
							
						}else if(res.data.code == -1){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}else if(res.data.code == 408){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
							uni.reLaunch({
								url: '/pages/admin/login'
							})
						}	
						
					}
				})
			}
		}
	}
</script>

<style scoped>
.content{
	min-height: 100vh;
	background-color: #F6f6f6;
}
.message-box{
	/* width: 100%; */
	min-height: 100%;
	padding: 28rpx;
}
.message-item{
	background-color: #fff;
	border-radius: 1rpx;
	padding: 20rpx 24rpx;
	margin-bottom: 27rpx;
}
.flex{
	display: flex;
	justify-content: space-between;
	align-items: center;
	line-height: 30px;
}
.msgtitle{
	font-weight: 600;
	font-size: 15px;
}
.money{
	color: #999;
}
.status{
	font-size: 25px;
}
.btns{
	padding: 10px;
	overflow: hidden;
}
.btn{
	width: 100px;
	float: right;
}
</style>
